<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ include file="/WEB-INF/component/commonTagLib.jsp" %> 
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>药品上报</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">交易</a></li>
            <li class="active"><a href="#">药品短缺管理</a></li>
            <li class="active"><a href="#">药品短缺上报</a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success">
           
            <!-- form start -->
            <form role="form" id="form1" class="form-horizontal" action="${ctx}/DrugShortage/saveDrugInfoRep.html" method="post">
                <div class="box-body">
                <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>通用名：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="drugName"  name="drugName" placeholder="通用名" type="text" readonly="readonly" value="${detail.drugName }">
                        </div>
                        <label class="col-sm-2 text-right"><span class="required">*</span>剂型：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="formName"  name="formName" placeholder="剂型" type="text" readonly="readonly" maxlength="100" value="${detail.formName }">
                        </div>
                </div>
                <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>规格：</label>
                        <div class="col-sm-4 text-left">
                        <input type="hidden"   id="specId" name="specId">
                            <input class="form-control"  id="specName"   name="specName" placeholder="规格" type="text" readonly="readonly" value="${detail.specName }">
                        </div>
                        <label class="col-sm-2 text-right"><span class="required">*</span>转换系数：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control"  id="factor" name="factor" placeholder="转换系数" type="text" readonly="readonly" value="${detail.factor }" >
                        </div>
                </div>
                <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>单位：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control"  id="unitName" name="unitName" placeholder="单位" type="text" readonly="readonly" value="${detail.unitName }">
                        </div>
                        <label class="col-sm-2 text-right"><span class="required">*</span>生产企业：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="compName" name="compName" placeholder="生产企业" type="text" readonly="readonly" value="${detail.catCompName }">
                        </div>
                 </div>
                 <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>药物属性：</label>
                        <div class="col-sm-4 text-left">
                            <%-- <input class="form-control"  id="drugAttr" name="drugAttr" placeholder="药物属性" type="text" readonly="readonly" value="${detail.drugAttr }"> --%>
                            <input class="form-control"  id="drugAttr" name="drugAttr" placeholder="药物属性" type="hidden" value="${detail.drugAttr }">
                            <select class="form-control" id="drugAttr" name="drugAttr" disabled="disabled">
                                <option value="">请选择</option>
                                <option value="1" ${ detail.drugAttr == 1 ? "selected='selected'" : "" } >国家基本药物</option>
                                <option value="2" ${ detail.drugAttr == 2 ? "selected='selected'" : "" } >省增补基本药物</option>
                                <option value="3" ${ detail.drugAttr == 3 ? "selected='selected'" : "" } >其他</option>
                            </select>
                        </div>
                        <label class="col-sm-2 text-right"><span class="required">*</span>国药准字：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="drugMedicine" name="drugMedicine" placeholder="国药准字" type="text" readonly="readonly" value="${detail.drugMedicine }">
                    	</div>
                 </div>
                 <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>年需求量：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" id="needCount" name="needCount" placeholder="年需求量" type="text" maxlength="10" value="">
                        </div>
                        <label class="col-sm-2 text-right"><span class="required">*</span>短缺时间（月）：</label>
                        <div class="col-sm-4 text-left">
                         	<input class="form-control" type="text" id="shortDate" name="shortDate" placeholder="yyyy-MM" data-provide="datepicker" data-date-fmt="yyyy-MM" />
                        </div>
                 </div>
                 <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>短缺类型：</label>
                        <div class="col-sm-4 text-left">
                            <select class="form-control" name="shortType" id="shortType">
                            <option value="" selected="selected">请选择</option>
                            <option value="1" >价格偏低</option>
                            <option value="2" >原材料短缺</option>
                            <option value="3">用量少</option>
                            <option value="9">其他</option>
                            </select>
                        </div>
                 </div>
                 <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>短缺原因：</label>
                        <div class="col-sm-10 text-left">
                            <textarea class="form-control" id="shortageReason" name="shortageReason" rows="3" maxlength="2000" placeholder="短缺原因"></textarea>
                        </div>
                        
                 </div>
                   <div class="form-group form-group-xs">
                        <label class="col-sm-2 text-right"><span class="required">*</span>申报备注：</label>
                        <div class="col-sm-10 text-left">
                            <textarea class="form-control" id="remark" name="remark" rows="3" maxlength="2000" placeholder="申报备注"></textarea>
                        </div>
                        
                 </div>
                    
                    
                 <div class="box-footer text-center">
                    <button type="button" onclick="save();" class="btn btn-success btn-sm">保&nbsp;存</button>
                    <button type="button" onclick="back();" class="btn btn-danger btn-sm">返&nbsp;回</button>
                </div>
              </div>
            </form>
        </div>
        
        
        
        <%@ include file="/WEB-INF/component/commonJS.jsp" %>  
    </section>
	<script type="text/javascript">
	$(document).ready(function (){
		var form1 = $("#form1").val();
		var form2 = $("#form2").val();
		$("#drugform1").HNSelect({
            url: "${pageContext.request.contextPath}/selectController/getForm.html", data: { ID: '0' },defaultselect:'${form.drugform1 }',  defaultText: "<option value=''>请选择</option>",
            func: function () {
                $("#drugform2").HNSelect({
                    parent_selector: "#drugform1", url: "${pageContext.request.contextPath}/selectController/getForm.html", dataid: "ID",defaultselect:'${form.drugform2 }',  defaultText: "<option value=''>请选择</option>",
                    
                });
            }
        });
		
	})
   function save(){
		if(testRepByDrugNameHosp()){
       		return;
       	}
    	
     }
	
	//校验通用名
	function testRepByDrugNameHosp(){
            var drugName = $.trim($("#drugName").val());
            var formName = $.trim($("#formName").val());
            var specName = $.trim($("#specName").val());
            var factor = $.trim($("#factor").val());
            var unitName = $.trim($("#unitName").val());
            var compName = $.trim($("#compName").val());
            var drugAttr = $.trim($("#drugAttr").val());
            $.post("testRepByDrugNameHosp.html", {
            	drugName : drugName,
            	formName : formName,
            	specName : specName,
            	factor : factor,
            	unitName : unitName,
            	compName : compName,
            	drugAttr : drugAttr
            }, function(result) {
                if (result) {
                    $.alert('药品当月已经上报，请下月在上报！',  'warn');
                    return false;
                } else{
                	if(!validateBase()){
               			return;
               		}
               	  $.HN.message.confirm('<spring:message code="message.HN.alert.OkSaveYESorNO"/>', '', '').on(function (e) {
                         if (e) {
                       	  $("#form1").ajaxSubmit({
                       		  dataType : "json",
                     		  timeout: 10000,
                     		success: function(result) {
                     		   	if(result.success) {
                     		   		$.alert('添加成功！', '提示信息', 'success');
                     		   	   window.location.href="${ctx }/DrugShortage/toDrugShortage.html";
                     			}else{
                     				$.alert('添加失败，请重新添加！', '提示信息', 'success');
                     		   	}
                     		      }
                 	   	  });
                       	  } 
               	  });
                }
            }, "json");
    }
   
   function validateBase() {
     var needCount = $.trim($("#needCount").val());
     if (needCount == null || needCount == "") {
         $.alert("请输入年需求量！",  "warn");
         return false;
     }
     $("#needCount").val(needCount);
     
     
     var shortDate = $.trim($("#shortDate").val());
     if (shortDate == null || shortDate == "") {
         $.alert("请输入短缺时间！",  "warn");
         return false;
     }
     $("#shortDate").val(shortDate);
     
     var shortType = $.trim($("#shortType").val());
     if (shortType == null || shortType == "") {
         $.alert("请选择短缺类型！",  "warn");
         return false;
     }
     $("#shortType").val(shortType);
     
     var shortageReason = $.trim($("#shortageReason").val());
     if (shortageReason == null || shortageReason == "") {
         $.alert("请输入短缺原因！",  "warn");
         return false;
     }
     $("#shortageReason").val(shortageReason);
     
     var remark = $.trim($("#remark").val());
     if (remark == null || remark == "") {
         $.alert("请输入申报备注！",  "warn");
         return false;
     }
     $("#remark").val(remark);
  	 
       return true;
   }

	
	
   function back(){
   	window.location.href="${ctx}/DrugShortage/toDrugShortage.html";
   }
  
	</script>
</body>
</html>